<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="demo">
        <p>todos: {{todos}}</p>
        <p>已完成 {{doneNum}}/ 全部 {{total}}</p>
        <p>全选反选: {{checkAllFlag}}</p>
    </div>
    <script>
        /**
         *  todos
         * 
         *  总条数
         *  已完成数量
         *  
         */
        Vue.config.productionTip = false
        new Vue({
            el: '#demo',
            data: {
                todos: [
                    {
                        id: 1,
                        title: '吃饭',
                        isDone: false
                    },
                    {
                        id: 2,
                        title: '睡觉',
                        isDone: false
                    },
                    {
                        id: 3,
                        title: '敲代码',
                        isDone: true
                    }
                ]
            },
            computed:{
                total(){
                    return this.todos.length
                },
                doneNum(){
                    return this.todos.reduce((pre,cur)=>pre+cur.isDone, 0)
                },
                /**
                 *  依赖于其他计算属性计算得来的计算属性
                 */
                checkAllFlag(){
                    return this.total === this.doneNum && this.total > 0
                }
            }
        })
    </script>
</body>

</html>